package client.ui.view.module;

import client.ui.theme.ThisFont;
import client.ui.util.MaterialBorder;
import client.entity.Record;
import client.ui.util.MaterialColors;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.text.SimpleDateFormat;

/**
  * @Description 一个已购买物品的显示
  * @author 孔明浩
  * @Date 2020/3/31
  */
public class BoughtItem extends JPanel {
    private Record record;
    public BoughtItem(Record record){
        super();
        this.record = record;
        initial();
    }

    private void initial(){
        this.setLayout(new BorderLayout());
        this.setBorder(MaterialBorder.NORMAL_LINE_BORDER);
        JLabel nameLabel = new JLabel(record.getGoodName() + "");
        nameLabel.setFont(ThisFont.MIDDLE_BOLD_FONT);
        nameLabel.setForeground(MaterialColors.COSMO_BLUE);
        nameLabel.setBorder(new EmptyBorder(12,12,12,12));
        JLabel priceLabel = new JLabel(record.getCount() + "*(￥" + record.getAmount() / record.getCount() + ")", SwingConstants.CENTER);
        priceLabel.setFont(ThisFont.SMALL_FONT);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        JLabel dateLabel = new JLabel(simpleDateFormat.format(record.getBoughtTime()), SwingConstants.CENTER);
        dateLabel.setFont(ThisFont.SMALL_FONT);

        this.add(nameLabel, BorderLayout.NORTH);
        this.add(priceLabel, BorderLayout.CENTER);
        this.add(dateLabel, BorderLayout.SOUTH);
    }
}
